<template>
  <view class="detail-page">
    <!-- 商品主图 -->
    <view class="product-banner">
      <image :src="BASE_URL + goodsDetail.headerImg || DEFAULT_IMAGE" mode="aspectFit" />
    </view>

    <!-- 商品信息 -->
    <view class="product-info">
      <view class="product-header">
        <view class="title">{{ goodsDetail.name }}</view>
      </view>

      <view class="price-section">
        <view class="price">
          <!-- <text class="symbol">¥</text>
          <text class="amount">{{ goodsDetail.price }}</text> -->
        </view>
      </view>

      <view class="info-item">
        <text class="label">商品编号</text>
        <text class="value">{{ goodsDetail.id }}</text>
      </view>

      <view class="info-item">
        <text class="label">商品规格</text>
        <text class="value">{{ goodsDetail.omsGoodsSkus?.map((sku) => `${sku.skuName}*1`).join("、") || "-" }}</text>
      </view>

      <view class="section-title">商品简介</view>
      <view class="description">{{ goodsDetail.description }}</view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { DEFAULT_IMAGE } from "@/config/images";
import { getGoodsDetail } from "@/api/goods";
import { BASE_URL, IMG_URL } from "@/utils/request";

// 商品详情
const goodsDetail = ref({
  id: "",
  name: "",
  price: "",
  typeId: 0,
  typeName: "",
  description: "",
  headerImg: "",
  status: 0,
  createTime: "",
  updateTime: "",
  omsGoodsSkus: [],
});

// 获取商品详情
const fetchGoodsDetail = async (id: string) => {
  try {
    const res = await getGoodsDetail(Number(id));
    goodsDetail.value = res.data;
  } catch (error) {
    console.error("获取商品详情失败:", error);
    uni.showToast({
      title: "获取商品详情失败",
      icon: "none",
    });
  }
};

// 页面加载
onLoad((options: any) => {
  const { id } = options;
  if (id) {
    fetchGoodsDetail(id);
  }
});
</script>

<style lang="scss" scoped>
.detail-page {
  min-height: 100vh;
  background: #fff;
  padding-bottom: 120rpx;
}

.product-banner {
  width: 100%;
  height: 750rpx;
  background: #f8f8f8;

  image {
    width: 100%;
    height: 100%;
  }
}

.product-info {
  padding: 30rpx;

  .product-header {
    margin-bottom: 20rpx;

    .title {
      font-size: 32rpx;
      color: #333;
      font-weight: bold;
      margin-bottom: 10rpx;
    }
  }

  .price-section {
    display: flex;
    align-items: baseline;
    margin-bottom: 30rpx;

    .price {
      color: #ff4b33;
      margin-right: 20rpx;

      .symbol {
        font-size: 24rpx;
      }

      .amount {
        font-size: 36rpx;
        font-weight: bold;
      }
    }
  }

  .info-item {
    display: flex;
    margin-bottom: 20rpx;

    .label {
      font-size: 28rpx;
      color: #666;
      margin-right: 20rpx;
      min-width: 140rpx;
    }

    .value {
      font-size: 28rpx;
      color: #333;
      flex: 1;
    }
  }

  .section-title {
    font-size: 32rpx;
    color: #333;
    font-weight: bold;
    margin: 40rpx 0 20rpx;
  }

  .description,
  .solution {
    font-size: 28rpx;
    color: #666;
    line-height: 1.6;
  }
}
</style>
